﻿Imports System.Collections.ObjectModel

Public Class LexiconSegment
    Private m_lexicalTokenList As ReadOnlyCollection(Of LexicalToken)

    Public Sub New(ByVal lexicalTokens As IList(Of LexicalToken))
        CodeContract.RequiresArgumentNotNull(lexicalTokens, "lexicalToken")
        m_lexicalTokenList = New ReadOnlyCollection(Of LexicalToken)(lexicalTokens)
    End Sub

    Public ReadOnly Property LexicalTokens As ReadOnlyCollection(Of LexicalToken)
        Get
            Return m_lexicalTokenList
        End Get
    End Property

    Public Function GenerateNFA() As NFAModel
        Dim entryState As New NFAState
        Dim combinedNFA As New NFAModel

        combinedNFA.AddState(entryState)
        For Each lexToken In m_lexicalTokenList
            Dim tokenNFA = lexToken.GenerateNFA()

            entryState.AddEdge(tokenNFA.EntryEdge)
            combinedNFA.AddStates(tokenNFA.States)
        Next

        combinedNFA.EntryEdge = New NFAEdge(entryState)

        Return combinedNFA
    End Function
End Class
